#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

int n, m, idx = 0, cnt = 0;
int a[N], b[N << 1], root[N];
vector<tuple<int, int, int>> q;
struct node
{
    int l, r, sum;
}tree[N << 5];

int update(int pre, int l, int r, int v)
{
    int rt = ++idx;
    tree[rt].l = tree[pre].l, tree[rt].r = tree[pre].r;
    tree[rt].sum = tree[pre].sum + 1;
    int mid = (l + r) >> 1;
    if (l < r) {
        if (v <= mid) tree[rt].l = update(tree[pre].l, l, mid, v);
        else  tree[rt].r = update(tree[pre].r, mid + 1, r, v);
    }
    return rt;
}

int query(int u, int v, int l, int r, int ql, int qr)
{
    if (l >= ql && r <= qr) return tree[v].sum - tree[u].sum;
    int mid = (l + r) >> 1, res = 0;
    if (ql <= mid) res += query(tree[u].l, tree[v].l, l, mid, ql, qr);
    if (qr > mid) res += query(tree[u].r, tree[v].r, mid + 1, r, ql, qr);
    return res;
}

void solve()
{
    idx = cnt = 0;
    q.clear();
    cin >> n >> m;
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
        b[++cnt] = a[i];
    }
    for (int i = 1;i <= m;i++) {
        int l, r, h;cin >> l >> r >> h;
        l++, r++;
        q.push_back( make_tuple(l,r,h) );
        b[++cnt] = h;
    }

    sort(b + 1, b + cnt + 1);
    int len = unique(b + 1, b + cnt + 1) - b - 1;

    for (int i = 1;i <= n;i++) {
        int x = lower_bound(b + 1, b + len + 1, a[i]) - b;
        root[i] = update(root[i - 1], 1, len, x);
    }

    for (int i = 0;i < q.size();i++) {
        int x = get<0>(q[i]), y = get<1>(q[i]), k = get<2>(q[i]);
        k = lower_bound(b + 1, b + len + 1, k) - b;
        int ans = query(root[x - 1], root[y], 1, len, 1, k);
        cout << ans << '\n';
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    cin >> T;
    for (int i = 1;i <= T;i++) {
        printf("Case %d:\n", i);
        solve();
    }
}